<template>
    <Modal v-model="show" :mask-closable="false" :closable="false" title="修改密码"
           @on-cancel="modelCancel">
        <Form :model="formItem" :label-width="80" ref="wlModelForm">
            <FormItem label="新密码">
                <Input v-model="formItem.pwd" placeholder="输入修改的密码..."></Input>
            </FormItem>
        </Form>
        <div slot="footer">
            <Button @click="modelCancel" :loading="loading">取消</Button>
            <Button type="success" @click="handleSubmit" :loading="loading">提交</Button>
        </div>
    </Modal>
</template>

<script>
import { userChangePwd } from '@/api/google'

export default {
  name: 'changePwd',
  props: {
    changeId: {
      type: String,
      default: () => {
        return ''
      }
    },
    show: {
      type: Boolean,
      default: () => {
        return false
      }
    }
  },
  data () {
    return {
      loading: false,
      formItem: { pwd: '' }
    }
  },
  created () {
  },
  methods: {
    handleReset () {
      this.$refs.wlModelForm.resetFields()
    },
    handleSubmit () {
      if (this.formItem.pwd === '') {
        this.$Message.error('请输入密码！')
        return false
      }
      let postData = { pwd: this.formItem.pwd }
      if (this.changeId !== '') {
        postData.changeId = this.changeId
      }
      userChangePwd(postData).then(ret => {
        if (ret.data.errcode === 1001) {
          this.$Message.success({
            content: '密码修改成功',
            onClose: () => {
              this.formItem.pwd = ''
              this.modelCancel()
            }
          })
        } else {
          this.$Message.error('密码修改失败！')
        }
      })
    },
    modelCancel () {
      this.$emit('cancelShow')
    },
    loadingRun () {
      this.loading = !this.loading
    }
  },
  watch: {
    show (value) {
      if (value === true) {
        this.loading = false
      }
    }
  }
}
</script>

<style scoped>

</style>
